<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.mongodb.client.MongoCursor, org.bson.Document, org.bson.types.ObjectId" %>
<%@ page import="mongo.Task, java.util.Date,java.text.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>任务详情</title>
</head>
<body>
	<%
		Task Task = new Task(); 
	  	ObjectId _id = new ObjectId(request.getParameter("_id"));
	  	Document document = Task.findByid(_id);
		String name = document.getString("name");
		String content = document.getString("content");
		String teachername = document.getString("teachername");
		String courseclassname = document.getString("courseclassname");
		String templatename = document.getString("templatename");
		String uploadfilename = document.getString("uploadfilename");
		String uploadfiledir = document.getString("uploadfiledir");
		Date date = document.getDate("createtime"); 
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String createtime = formatter.format(date);
		boolean isfinish = document.getBoolean("isfinish");
	%>
	<jsp:include page="../navbar.jsp" />
	<div class="col-md-10 col-md-offset-1">
    	<div class="panel">
      		<div class="panel-body" style="padding:25px">
        		<div style="display:inline">
        			<h3 style="display:inline"><%=name %></h3>
        			<span class="badge" style="background-color:#eee;color:#777;padding:6px 12px;margin:-6px 0 0 20px"><em class="fa fa-flag">  相关课程：<%=courseclassname %></em></span>
        		</div>
        		<div class="pull-right" style="margin-top:5px">
        			<em class="fa fa-clock-o text-muted mr20"> 创建时间：<%=createtime %></em> 
	             	<%if(isfinish) {%>
	             		<span class="badge" style="background-color:#5cb85c">已完成</span>
	             	<%}
	             	else {%>
	             		<span class="badge" style="background-color:#f0ad4e">未完成</span>
	             	<%} %>
	             
	             </div>
       	 	</div>
     	</div>
     	<div class="panel">
     		<div class="panel-body">
     			<h4 class="page-header mt0">
     				<em class="fa fa-flask text-muted"> 任务内容</em>
     			</h4>
     			<%=content %>
       	 	</div>
       	 	<div class="panel-body">
     			<h4 class="page-header mt0">
     				<em class="fa fa-file-o text-muted"> 附属文件</em>
     			</h4>
     			<div style="display:inline">
        			<em class="fa fa-file fa-3x text-muted"></em> 
        			<span style="margin-left:20px"><%=templatename %></span>		
        		</div>
        		<div class="pull-right" style="margin-top:5px">
        			<a href="/jspbighomework/downloadServlet?filename=<%=templatename %>">
	             		<button class="btn btn-primary"><em class="fa fa-download"></em> 下载文件</button>
	             	</a>
	            </div>
       	 	</div>
     	</div>
     	<%if(isfinish) {%>
        <div class="panel panel-success">
	      	<div class="panel-heading">已上传材料</div>
	      	 <div class="panel-body">
	      	 	<div style="display:inline">
        			<em class="fa fa-file fa-3x text-muted"></em> 
        			<span style="margin-left:20px"><%=uploadfilename %></span>		
        		</div>
        		<div class="pull-right" style="margin-top:5px">
        			<a href="/jspbighomework/downloadServlet?filename=<%=uploadfilename %>">
	             		<button class="btn btn-primary"><em class="fa fa-download"></em> 下载文件</button>
	             	</a>
	            </div>
	      	 </div>
	    </div>
	  <%} else {%>
	  	<div class="panel panel-info">
	      	<div class="panel-heading">上传材料</div>
	      	 <div class="panel-body">
	      	 	<form name="taskform" role="form" action="/jspbighomework/manager/userManage/UploadServlet" method="post" enctype="multipart/form-data" onsubmit="return check(this);" class="form-horizontal">
	      	 		<input type="hidden" name="taskid" value="<%=_id%>">   
		            <div class="form-group ml20">
		              	<a href="javascript:;" class="file">选择文件
					     	<input type="file" name="file" />
					  	</a>
			            <span class="showFileName">
			             	未选择任何文件
			            </span>
						<button type="submit" class="btn btn-primary ml20" name="task">确定</button> 
		            </div> 		                 		          	               		
            	</form>
	      	 </div>
	    </div>
	  <%} %>
   </div>
   <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
	<script>
	$(document).ready(function(){
		$(".file").on("change","input[type='file']",function(){
		    var filePath=$(this).val();
		    if(filePath!=null || filePath!=""){
		        var arr=filePath.split('\\');
		        var fileName=arr[arr.length-1];
		        $(".showFileName").text(fileName);
		    }else{
		        $(".showFileName").text("未选择任何文件");
		        return false; 
		    }
		})
	});
	function check(taskform) {  
	    if (taskform.file.value == "") {
	        swal("没有选择文件","请选择要上传的文件", "warning");
	        return false;
	    }
	    
	    return true;  
	}    
	</script>
</body>
</html>
